Telegram Group & Telegram Channel
3 способа преобразования массива в объект

Приветствую товарищи! Довольно часто по разным причинам нам требуется трансформировать данные в какой-либо формат, например для работы с какой-нибудь библиотекой или апихой. В этом посте описаны 3 способа с помощью которых можно массив трансформировать в объект.

const arr = ['frontend', 'backend', 'qa'];

// 1 способ - метод assign
const obj = Object.assign({}, arr);

// 2 способ - spread оператор
const obj = {...arr};

// 3 способ - метод reduce
const obj = arr.reduce((res, key, index) => {
res[index] = key;
return res;
}, {})

#js #features



tg-me.com/projavascript/155
Create:
Last Update:

3 способа преобразования массива в объект

Приветствую товарищи! Довольно часто по разным причинам нам требуется трансформировать данные в какой-либо формат, например для работы с какой-нибудь библиотекой или апихой. В этом посте описаны 3 способа с помощью которых можно массив трансформировать в объект.

const arr = ['frontend', 'backend', 'qa'];

// 1 способ - метод assign
const obj = Object.assign({}, arr);

// 2 способ - spread оператор
const obj = {...arr};

// 3 способ - метод reduce
const obj = arr.reduce((res, key, index) => {
res[index] = key;
return res;
}, {})

#js #features

BY Javascript Pro


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/projavascript/155

View MORE
Open in Telegram


Javascript Pro Telegram | DID YOU KNOW?

Date: |

At a time when the Indian stock market is peaking and has rallied immensely compared to global markets, there are companies that have not performed in the last 10 years. These are definitely a minor portion of the market considering there are hundreds of stocks that have turned multibagger since 2020. What went wrong with these stocks? Reasons vary from corporate governance, sectoral weakness, company specific and so on. But the more important question is, are these stocks worth buying?

What is Secret Chats of Telegram

Secret Chats are one of the service’s additional security features; it allows messages to be sent with client-to-client encryption. This setup means that, unlike regular messages, these secret messages can only be accessed from the device’s that initiated and accepted the chat. Additionally, Telegram notes that secret chats leave no trace on the company’s services and offer a self-destruct timer.

Javascript Pro from pl


Telegram Javascript Pro
FROM USA